//
// Created by Administrator on 2023/8/4.
//

#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

class Solution {
public:
    int findMaxK(vector<int> &nums) {
        unordered_set<int> set;
        int maxVal = -1;
        for (auto &x: nums) {
            if (set.find(-x) != set.end())
                maxVal = max(maxVal, abs(x));
            else
                set.insert(x);
        }
        return maxVal;
    }
};

class Solution2 {
public:
    int findMaxK(vector<int> &nums) {
        sort(nums.begin(), nums.end());
        for (int i = 0, j = nums.size() - 1; i < j; j--) {
            while (i < j && nums[i] < -nums[j]) {
                i++;
            }
            if (nums[i] == -nums[j]) {
                return nums[j];
            }
        }
        return -1;
    }
};


int main() {
    Solution s;
    vector<int> nums = {-10, 8, 6, 7, -2, -3};
    int maxK = s.findMaxK(nums);
    cout << maxK << endl;
    return 0;
}